package com.rxyb.wechat.gateway.controller;


import com.rxyb.core.respone.R;
import com.rxyb.wechat.gateway.dto.tools.*;
import com.rxyb.wechat.service.WechatToolsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 微信推送记录 前端控制器
 * </p>
 *
 * @author DUYH
 * @since 2020-06-12
 */
@RestController
@RequestMapping(value = "/wechat/tools", produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
public class WechatToolsController {

    @Autowired
    private WechatToolsService wechatToolsService;

    /**
     * 根据地址获取经纬度
     *
     * @author duyh
     */
    @PostMapping(value = "getLocation", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public R<GetLocationRsp> getLocation(@Validated @RequestBody GetLocationReq getLocationReq) {
        return wechatToolsService.getLocation(getLocationReq);
    }

    /**
     * 获取两个位置间的距离
     *
     * @author duyh
     */
    @PostMapping(value = "getDistance", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public R<GetDistanceRsp> getDistance(@Validated @RequestBody GetDistanceReq getDistanceReq) {
        return wechatToolsService.getDistance(getDistanceReq);
    }

    /**
     * 发送模板消息
     *
     * @author duyh
     */
    @PostMapping(value = "sendTemplate", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public R<SendWechatTemplateRsp> sendTemplate(@Validated @RequestBody SendWechatTemplateReq sendWechatTemplateReq) {
        return wechatToolsService.sendTemplate(sendWechatTemplateReq);
    }

}
